using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PhysicsCheck : MonoBehaviour
{
    public Boolean manualOffset;
    public Boolean isOnGround;
    public Boolean isTouchLeftWall;
    public Boolean isTouchRightWall;

    public float checkRadius;

    
    public Vector2 bottomOffset;
    public Vector2 leftOffset;
    public Vector2 rightOffset;
    public LayerMask whatIsGround;

    private CapsuleCollider2D cc2d;

    private void Awake()
    {
        cc2d= GetComponent<CapsuleCollider2D>();
        if (!manualOffset)
        {

                leftOffset= new Vector2(-cc2d.bounds.size.x/2+cc2d.offset.x/2,cc2d.bounds.size.y/2);

     
                rightOffset= new Vector2(cc2d.bounds.size.x/2+cc2d.offset.x/2,cc2d.bounds.size.y/2);

        }
    }

    void Check()
    {
       isOnGround= Physics2D.OverlapCircle((Vector2)transform.position + bottomOffset, checkRadius, whatIsGround);
       isTouchLeftWall = Physics2D.OverlapCircle((Vector2)transform.position + leftOffset, checkRadius, whatIsGround);
       isTouchRightWall = Physics2D.OverlapCircle((Vector2)transform.position + rightOffset, checkRadius, whatIsGround);

    }
    
    private void Update() {
        Check();
    }

    private void OnDrawGizmosSelected() 
    {
        Gizmos.DrawWireSphere((Vector2)transform.position+bottomOffset,checkRadius);
        Gizmos.DrawWireSphere((Vector2)transform.position+leftOffset,checkRadius);
        Gizmos.DrawWireSphere((Vector2)transform.position+rightOffset,checkRadius);
    }
}
